package com.server.user.controller;

import com.server.model.all.constant.preAuthorize.RolePreAuthorizeConstant;
import com.server.common.security.code.SecurityUtils;
import com.server.common.security.code.anntation.PreAuthorize;
import com.server.model.all.user.bo.RoleAddBo;
import com.server.model.all.user.dto.RoleAddDto;
import com.server.user.service.RoleService;
import com.server.common.code.utils.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 角色
 * @author LXC
 * @date 2022/5/5 13:17
 */
@RestController
@RequestMapping(path = "/systemRole")
@Api(value = "角色",tags = "角色")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     * 添加角色
     * @author LXC
     * @date 2022/5/4 20:41
     */
    @PostMapping("/roleAdd")
    @PreAuthorize(hasPre = RolePreAuthorizeConstant.ROLE_ADD)
    @ApiOperation(value = "添加角色",notes = RolePreAuthorizeConstant.ROLE_ADD)
    public AjaxResult roleAdd(@RequestBody @Validated RoleAddDto roleAddDto){
        RoleAddBo roleAddBo = new RoleAddBo();
        BeanUtils.copyProperties(roleAddDto,roleAddBo);
        roleAddBo.setCreateUserId(SecurityUtils.getLoginVo().getUserId());
        return AjaxResult.successData(roleService.roleAdd(roleAddBo));
    }


}
